import { Application } from 'egg';
import { STRING, INTEGER, JSON, Optional, Model } from 'sequelize';

export interface ActiveAttributes {
  activeId: number;
  userId: number;
  text: string;
  photos: string[];
  time: number;
}

interface ActiveCreationAttributes extends Optional<ActiveAttributes, 'activeId'> {}

export default (app: Application) => {
  const User = app.model.define<Model<ActiveAttributes, ActiveCreationAttributes>>('active', {
    activeId: { type: INTEGER, primaryKey: true, autoIncrement: true, field: 'activeId' },
    userId: { type: INTEGER, allowNull: false, field: 'userId' },
    text: { type: STRING(1000), allowNull: false },
    photos: { type: JSON, allowNull: false },
    time: { type: INTEGER, allowNull: false },
  }, {
    timestamps: false,
  });

  return User;
};
